import Mock from "mockjs";
import qs from "qs";
//mock的配置
Mock.setup({
  //模拟网络延迟
  timeout: "500-1000",
});

//拦截接口
//1.路由规则（请求地址）
//2.请求方式
//3.返回数据

//模拟 我的收藏接口
Mock.mock(/\/member\/collect/, "get", (config) => {
  const queryString = config.url.split("?")[1];
  const queryObject = qs.parse(queryString);
  const item = [];
  for (let i = 0; i < +queryObject.pageSize; i++) {
    item.push(
      Mock.mock({
        id: "@id",
        name: "@ctitle(10,20)",
        description: "@ctitle(4,10)",
        price: "@float(100,200,2,2)",
        picture: `http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/clothes_goods_${Mock.mock(
          "@integer(1,8)"
        )}.jpg`,
      })
    );
  }

  return {
    msg: "获取收藏商品成功",
    result: {
      counts: 35,
      pageSize: +queryObject.pageSize,
      page: +queryObject.page,
      item,
    },
  };
});
